package com.example.administrator.fangbook.utils;

import android.app.Activity;
import android.graphics.Color;
import android.os.Build;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

/**
 * 作者 ： liyinqing on 2018/11/9 0009
 * 邮箱 ：yinqing_521@163.com
 */
public class StateViewSet {


    public static void setStateView(Activity activity, StateIndicate indicate, boolean ishide) {
        if (indicate == StateIndicate.STATE_LUCENCY) {
            //沉浸式
            fullScreen(activity, ishide);
        } else if (indicate == StateIndicate.STATE_NORMAL) {
            //正常设定颜色
        }
    }

    /**
     * 沉浸式只有android api 19 的才支持
     * @param activity
     * @param ishide
     */
    public static void fullScreen(Activity activity, boolean ishide) {
        Window window = activity.getWindow();
        View decorView = window.getDecorView();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            if (ishide) {
                //View.SYSTEM_UI_FLAG_FULLSCREEN:表示全屏的意思，也就是会将状态栏隐藏
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
                }
            } else {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    //SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN设定系统UI全屏
                    //SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN和SYSTEM_UI_FLAG_LAYOUT_STABLE，
                    // 注意两个Flag必须要结合在一起使用，表示会让应用的主体内容占用系统状态栏的空间
                    //View.SYSTEM_UI_FLAG_HIDE_NAVIGATION隐藏导航栏
                    int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
                    //隐藏导航栏
                    int option1 = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
                    decorView.setSystemUiVisibility(option);
                    //导航栏颜色设置透明
                    window.setStatusBarColor(Color.TRANSPARENT);
                } else {
                    WindowManager.LayoutParams attributes = window.getAttributes();
                    int flagTranslucentStatus = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
                    int flagTranslucentNavigation = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;
                    // attributes.flags |= flagTranslucentNavigation; window.setAttributes(attributes);
                    attributes.flags |= flagTranslucentStatus;
                }
            }
        }
    }

    public enum StateIndicate {
        /**
         * 透明侵入
         */
        STATE_LUCENCY,
        /**
         * 正常，颜色
         */
        STATE_NORMAL
    }
}
